<template>
  <!-- 运输单位类型列表-->
  <div>
    <el-table v-loading="loading" :data="transportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="运输单位类型" prop="transportUnitTypeId" width="120" />
      <el-table-column label="描述" prop="description" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="重量能力" prop="weightCapacity" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="重量计量单位" prop="uomForWeight" width="100" />
      <el-table-column label="体积容量" prop="volumeCapacity" width="100" />
      <el-table-column label="体积计量单位" prop="uomForVolume" width="100" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['transport:list:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['transport:list:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { listTransport,listIsoUnit,getTransport,delTransport,addAndUpdateTransport,importTemplate,exportTransport,addTransport,updateTransport } from "@/api/erp/transport/transport";
  export default {
    name: 'Table',
    props:{
      queryParams:Object
    },
    data(){
      return {
        getListStr:false,
        //表格数据
        transportList:[],
        loading:false,
        total:0,
        addOrEit:{
          ids:[],
          open :false,
          single:false,
          form:{},
          title:"",
          multiple:false,
        }
      }
    },
    created() {
      this.getList();
    },
    watch:{
      queryParams:{
        handler: function(val) {
          console.log(val)
          this.getList();
        },
        deep: true
      },
      getListStr:function(val) {
        console.info(val)
        if(val){
          this.getList();
        }
        this.getListStr=false
      },
    },
    methods: {
      /** 查询运输单位类型列表 */
      getList() {
        this.loading = true;
        listTransport(this.queryParams).then(
          response => {
            this.transportList = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
      },
      /**多选框选中数据 */
      handleSelectionChange(selection) {
        this.addOrEit.ids = selection.map(item => item.transportUnitTypeId)
        this.addOrEit.single = selection.length!=1
        this.addOrEit.multiple = !selection.length
        this.$emit("update:single", this.addOrEit.single);
        this.$emit("update:multiple", this.addOrEit.multiple);
        this.$emit("update:ids", this.addOrEit.ids);
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        const id = row.transportUnitTypeId || this.ids;
        getTransport(id).then(response => {
          this.addOrEit.form = response.data;
          this.addOrEit.open = true;
          this.addOrEit.title = "修改运输单位类型";
          this.$emit("addOrEit", this.addOrEit);
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.transportUnitTypeId || this.ids;
        var str = "";
        if(ids.length>0&&ids.length<=3){
          str = '是否确认删除运势单位类型为"' + ids + '"的数据项?';
        }else if(ids.length>=4){
          str = '是否确认删除选择的"' + ids.length + '"项运输单位类型数据?';
        }else{
          str ='是否确认删除所有数据';
        }
        this.$confirm(str, "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTransport(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      }
    }
  }
</script>

<style scoped>

</style>
